package stackAndQueue;
/**
 * https://leetcode.com/problems/daily-temperatures/
 */
public class SingleStack {
	private static int MAX = 100001;
    public static int[] stack = new int[MAX];
    public static int r;
    public int[] dailyTemperatures(int[] temperatures) {
        int n = temperatures.length;
        r = 0;
        int[] ans = new int[n];
        for(int i=0;i<n;i++){
            while(r > 0 && temperatures[stack[r-1]] < temperatures[i]){
                int pos = stack[--r];
                ans[pos] = i - pos;
            }
            stack[r++] = i;
        }
        return ans;
    }
}
